//
//  IntegralDetailViewController.m
//  share_business
//
//  Created by baidufz on 2017/8/27.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "IntegralDetailViewController.h"
#import "CommonAmountHeaderCell.h"
#import "CommonDetailTitleCell.h"
#import "CommonDetailItemCell.h"
#import "UICollectionView+RegisterCell.h"
#import "SpaceCell.h"


@interface IntegralDetailViewController () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation IntegralDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self registerCells];
    [self initIntegralDetail];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self defaultMessageRightButton];
}

- (void)initIntegralDetail {
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
}

- (void)registerCells {
    [_collectionView registerHeaderCell:[CommonAmountHeaderCell class]];
    [_collectionView registerHeaderCell:[CommonDetailTitleCell class]];
    [_collectionView registerCell:[CommonDetailItemCell class]];
    [_collectionView registerFooterCell:[SpaceCell class]];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 1) {
        return 5;
    }
    return 0;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if ([kind isEqualToString:UICollectionElementKindSectionHeader] && indexPath.section == 0) {
        CommonAmountHeaderCell *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:NSStringFromClass([CommonAmountHeaderCell class]) forIndexPath:indexPath];
        
        return header;
    } else if([kind isEqualToString:UICollectionElementKindSectionHeader] && indexPath.section == 1) {
        CommonDetailTitleCell *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:NSStringFromClass([CommonDetailTitleCell class]) forIndexPath:indexPath];
        
        return header;
    } else if([kind isEqualToString:UICollectionElementKindSectionFooter]){
        SpaceCell *footer = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:NSStringFromClass([SpaceCell class]) forIndexPath:indexPath];
        footer.backgroundColor = [UIColor lightGrayColor];
        return footer;
    }
    return nil;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        CommonDetailItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([CommonDetailItemCell class]) forIndexPath:indexPath];
        
        return cell;
    }
    return nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(ScreenWidth, 60);
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    CGSize size = CGSizeMake(0, 0);
    if (section == 0) {
        size = CGSizeMake(ScreenWidth, 176);
    } else if (section == 1) {
        size = CGSizeMake(ScreenWidth, 45);
    }
    return size;
}

/** 底部的尺寸*/
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return CGSizeMake(1, 10);
    }
    return CGSizeMake(0, 0);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
